package com.cardone.platform.authority.validator;

import lombok.NonNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.cardone.platform.authority.dto.RolePermissionDto;
import com.cardone.platform.authority.service.AuthorityService;

/**
 * 角色与许可
 * 
 * @author yaoht
 * 
 */
@Component(RolePermissionValidator.BEAN_ID)
public class RolePermissionValidator implements Validator {
	/**
	 * spring bean id
	 */
	public static final String BEAN_ID = "com.cardone.platform.authority.validator.RolePermissionValidator";

	/**
	 * 许可服务
	 */
	@Qualifier(AuthorityService.BEAN_ID)
	@Autowired(required = false)
	private AuthorityService authorityService;

	@Override
	public boolean supports(@NonNull Class<?> clazz) {
		return RolePermissionDto.class.equals(clazz);
	}

	@Override
	public void validate(@NonNull Object target, @NonNull Errors errors) {
		// RolePermissionDto rolePermission = (RolePermissionDto) target;
		//
		// if (StringUtils.isBlank(rolePermission.getCode())) {
		// errors.reject("rolePermission.code.required", "编号不能为空");
		// }
	}
}
